using System;
using System.ComponentModel;
namespace Foundry.Engine
{
	[Serializable]
	public class BaseObject
	{
		[NonSerialized]
		private Snapshot snap;
		
		private Snapshot Snapshot { get { return snap; } set { snap = value; } }
		
		private bool enabled = true;
		private bool visible = true;
		
		internal volatile bool initialized;
		
		/// <summary>
		/// Determines if framestepping will occur on the object 
		/// </summary>
		[DefaultValue(true)]
		public bool Enabled { get { return enabled; } set {enabled = value;} }
		
		/// <summary>
		///Determines if drawing will occur for the object 
		/// </summary>
		[DefaultValue(true)]
		public bool Visible { get { return visible;} set { visible = true; } }
		
		[Action("Draw")]
		public Action DrawAction;
		[Action("Initialize")]
		public Action InitAction;
		[Action("Step")]
		public Action StepAction;
		[Action("DebugDraw")]
		public Action DebugDraw;
		
		public BaseObject Clone(bool recursive)
		{
			BaseObject ret = Activator.CreateInstance(GetType()) as BaseObject;
			
			var fields = GetType().GetFields();
			
			foreach(var field in fields)
			{
				if(recursive)
				{
					if(field.FieldType.IsSubclassOf(typeof(BaseObject)))
					{
						var val = (field.GetValue(this) as BaseObject);
						if(val != null)
							field.SetValue(ret, val.Clone(true));
						else
							field.SetValue(ret, null);							
					}
					else
						field.SetValue(ret, field.GetValue(this));
					
				}
				else
					field.SetValue(ret, field.GetValue(this));
			}
			
			return ret;
		}
		
		public int Handle { get; internal set; }
		
		public override int GetHashCode ()
		{
			return Handle;
		}
		
	
		public Scene Scene { get; set; }
		public BaseObject ()
		{
		}
	}
}

